package com.lv.suyiyong.hfrwork.adapter

import android.widget.EditText
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.constraintlayout.widget.ConstraintLayout
import com.blankj.utilcode.util.SizeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.DraggableModule
import com.lv.common.imp.OnPositionTListener
import com.lv.common.widget.recyclerview.DragTouchHolder
import com.lv.suyiyong.hfrwork.R
import com.lv.suyiyong.hfrwork.databinding.ItemBnameBinding


/**
 * 作者： ygx
 * 创建日期：2022/6/24 8:10 PM
 * 签名： 天行健，君子以自强不息；地势坤，君子以厚德载物。
 *      _              _           _     _   ____  _             _ _
 *     / \   _ __   __| |_ __ ___ (_) __| | / ___|| |_ _   _  __| (_) ___
 *    / _ \ | '_ \ / _` | '__/ _ \| |/ _` | \___ \| __| | | |/ _` | |/ _ \
 *   / ___ \| | | | (_| | | | (_) | | (_| |  ___) | |_| |_| | (_| | | (_) |
 *  /_/   \_\_| |_|\__,_|_|  \___/|_|\__,_| |____/ \__|\__,_|\__,_|_|\___/
 *
 * You never know what you can do until you try !
 * ----------------------------------------------------------------
 *
 */
class BnamesAdapter(private val datas: MutableList<String>) :
    BaseQuickAdapter<String, DragTouchHolder>
        (R.layout.item_bname, datas), DraggableModule {

    override fun convert(helper: DragTouchHolder, item: String) {
        val mBinding: ItemBnameBinding =
            helper.getBind() as ItemBnameBinding
        mBinding.itemRoot = item
//        //防止列表闪烁
        mBinding.executePendingBindings()
        val layoutPosition = helper.layoutPosition
        val clParent = helper.getView<ConstraintLayout>(R.id.cl_parent)
        val ivCut: ImageView = helper.getView<ImageView>(R.id.iv_cut)
//        val tvName: TextView = helper.getView<TextView>(R.id.tv_name)
//        tvName.text = item.name
        val layoutParams = clParent.layoutParams as FrameLayout.LayoutParams
        if (layoutPosition == datas.size - 1) {
            layoutParams.bottomMargin = SizeUtils.dp2px(40.0f)
        } else {
            layoutParams.bottomMargin = SizeUtils.dp2px(0.0f)
        }
        clParent.layoutParams = layoutParams
        ivCut.setOnClickListener {
            onViewCutClickListener?.onClick(layoutPosition, item)
        }

    }

    var onEditorFocusListener: OnPositionTListener<EditText>? = null
    var onViewCutClickListener: OnPositionTListener<String>? = null


}